package com.zmn.uac.client;

import com.alibaba.fastjson.JSON;
import com.zmn.base.channel.common.dro.ChannelDRO;
import com.zmn.base.channel.dubbo.interfaces.channel.ChannelListRemoteService;
import com.zmn.common.dto2.ResponseDTO;
import com.zmn.uac.UacException;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Component;

/**
 * @title: 渠道查询服务Dubbo接口
 * @author:Rananquan
 * @Date:2022/6/9 11:09
 */
@Slf4j
@Component
public class ChannelListClient {

    @DubboReference(version = com.zmn.base.plat.engine.common.constant.DubboConsts.INTERFACE_VERSION, check = false)
    ChannelListRemoteService channelListRemoteService;

    /**
     * 获取渠道信息
     * @param channelId 渠道ID
     * @return
     */
    public ChannelDRO getByChannelId(Integer channelId){
        log.info("获取渠道信息入参：{}",channelId);
        ResponseDTO<ChannelDRO> channelResponse = channelListRemoteService.getByChannelId(channelId);
        if(!channelResponse.isSuccess()){
            log.error("获取渠道信息请求失败，失败原因：{}",channelResponse.getMessage());
            throw new UacException(channelResponse.getMessage());
        }

        ChannelDRO channel = channelResponse.getData();
        log.info("获取渠道信息返回response：{}", JSON.toJSONString(channel));

        return channel;
    }
}
